package com.marvels.financial.loan.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.loan.dto.AnalysisStatisticalConditionDTO;
import com.marvels.financial.loan.dto.BusinessOverviewDataDTO;
import com.marvels.financial.loan.dto.PersonalPerformanceParamDTO;
import com.marvels.financial.loan.dto.PersonalPerformanceResultDTO;
import com.marvels.financial.loan.service.AnalysisStatisticalApi;

@Controller
@RequestMapping("financial/loan/analysisStatistic/service")
public class AnalysisStatisticalController {
	
	@Autowired
	private AnalysisStatisticalApi analysisStatisticalApi;
	
	/**
	 * 查询数据总览-业务概况数据
	 * @param conditionDTO
	 * @return
	 */
	@RequestMapping("/businessOverview")
	@ResponseBody
	public MarvelsResultDTO businessOverview(@RequestBody AnalysisStatisticalConditionDTO conditionDTO){
		try {
			BusinessOverviewDataDTO dataDTO=analysisStatisticalApi.businessOverview(conditionDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), dataDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询数据总览-业务概况数据FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询数据总览-业务概况数据异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询数据总览-业务概况数据异常", null);
		}
	}
	
	
	
	
	/**
	 * 查询数据总览-经营分析表格1数据
	 * @param conditionDTO
	 * @return
	 */
	@RequestMapping("/businessAnalysisTable1")
	@ResponseBody
	public MarvelsResultDTO businessAnalysisTable1(@RequestBody AnalysisStatisticalConditionDTO conditionDTO){
		try {
			Map<String, Object> map=analysisStatisticalApi.businessAnalysisTable1(conditionDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), map);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询数据总览-经营分析表格1数据FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询数据总览-经营分析表格1数据异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询数据总览-经营分析表格1数据异常", null);
		}
	}
	
	
	
	/**
	 * 查询数据总览-经营分析表格2数据
	 * @param conditionDTO
	 * @return
	 */
	@RequestMapping("/businessAnalysisTable2")
	@ResponseBody
	public MarvelsResultDTO businessAnalysisTable2(@RequestBody AnalysisStatisticalConditionDTO conditionDTO){
		try {
			Map<String, Object> map=analysisStatisticalApi.businessAnalysisTable2(conditionDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(),map);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询数据总览-经营分析表格2数据FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询数据总览-经营分析表格2数据异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询数据总览-经营分析表格2数据", null);
		}
	}
	
	
	/**
	 * 查询个人业绩信息
	 * @param personalPerformanceParamDTO
	 * @return
	 */
	@RequestMapping("/queryPersonalPerformanceList")
	@ResponseBody
	public MarvelsResultDTO queryUserChannelList(@RequestBody PersonalPerformanceParamDTO personalPerformanceParamDTO){
		try {
			List<PersonalPerformanceResultDTO> list = analysisStatisticalApi.queryPersonalPerformanceList(personalPerformanceParamDTO);
			MarvelsLogUtil.getInstance().info("查询个人业绩信息返回结果=======》》》" + list);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), list);
		}catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error("查询个人业绩信息异常=======》》》", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("查询个人业绩信息异常=======》》》", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
}
